$(function() { new EmbeddedController(); });

/**
 * @constructor
 */
function EmbeddedController()
{
	"use strict";

	/** @type {EmbeddedUrl} */
	var _url = new EmbeddedUrl();
	/** @type {EmbeddedView} */
	var _view = new EmbeddedView();
	/** @type {Set} */
	var _set = null;			// current set
	/** @type {Flickr} */
	var _flickr = new Flickr(Enum.flickr.key, Enum.flickr.secret);
	/**
	 * Size URLs to load from Flickr
	 * @type {Array.<String>}
	 */
	var _photoSizes = [Enum.size.large1024, Enum.size.large1600	];
	// 1000x700

	function init()
	{
		_view.slideshow.next = nextPhoto;
		_view.navigation.next = nextPhoto;
		_view.navigation.previous = previousPhoto;
		_view.updateSiteLink(_url.setID);

		_set = new Set({ id: _url.setID, title: Enum.title });

		_set.load(_flickr, _photoSizes, function()
		{
			_set.beginPhotoDownload();
			_view.slideshow.active = true;   // start slideshow after first image is loaded
			_view.photo.show(_set, _view.slideshow.start);
		});
	}

//- Navigation handlers -------------------------------------------------------

	/**
	 * Show the next photo
	 */
	function nextPhoto()
	{
		if (_set.nextPhoto()) { _view.photo.show(_set); }
	}

	/**
	 * Show the previous photo
	 */
	function previousPhoto()
	{
		if (_set.previousPhoto()) { _view.photo.show(_set); }
	}

	init();
}